package thesis;
import java.util.ArrayList;
import java.util.List;

import org.bson.BSONObject;

import com.mongodb.BasicDBList;
import com.mongodb.DBObject;


public class InternTweetInfoExtractor extends TweetInfoExtractor{
	private DBObject tweet;
	
	public InternTweetInfoExtractor(DBObject tweet) {
		this.tweet = tweet;
	}
	
	public long getId() {
		String id = tweet.get("tweet_id").toString();
		
		return Long.parseLong(id);
	}

	public String getText() {
		String text = tweet.get("text").toString();
			
		return text;
	}
	
	public String getPreprocessedText(){
		String preprocessedText = tweet.get("preprocessed_text").toString();
		
		return preprocessedText;
	}

	public long getTimestamp() {
		long timestamp = Long.parseLong((String)tweet.get("timestamp"));
		
		return timestamp;
	}

	public BasicDBList getCoordinates() {
		BasicDBList coordinates = (BasicDBList)tweet.get("coordinates");

		return coordinates;
	}

	public boolean hasCoordinates() {
		Object coordinates = tweet.get("coordinates");
		
		if (coordinates != null){
			return true;
		}
		else{
			return false;
		}
	}
	
	public Double getLatitude() {
		if(hasCoordinates()){
			BasicDBList coordinates = getCoordinates();
			double latitude = Double.parseDouble("" + coordinates.get(0));
			return latitude;
		}
		else{
			return null;
		}
	}

	public Double getLongitude() {
		if(hasCoordinates()){
			BasicDBList coordinates = getCoordinates();
			double longitude = Double.parseDouble("" + coordinates.get(1));
			return longitude;
		}
		else{
			return null;
		}
	}
	
	public double getQuality(){
		Double quality = (Double)((BSONObject)tweet.get("quality")).get("total");
		
		return quality;
	}
	
	public double getInfo(){
		Double info = (Double)((BSONObject)tweet.get("quality")).get("info");
		
		return info;
	}
	
	public List<Relevance> getRelevanceList(){
		BasicDBList relevanceList = (BasicDBList)((BSONObject)tweet.get("quality")).get("relevances");
		List<Relevance> relevances = new ArrayList<Relevance>();
		
		for (int i=0; i<relevanceList.size(); i++){
			DBObject relObject = (DBObject)relevanceList.get(i);
			String conceptId = relObject.get("concept").toString();
			double relevanceValue = Double.parseDouble("" + relObject.get("relevance"));
			Relevance relevance = new Relevance(conceptId, relevanceValue);
			relevances.add(relevance);
		}
		
		return relevances;
	}

	public String getLocationCategory(){
		Object locationCat = tweet.get("location_cat");
		
		if(locationCat != null)
			return locationCat.toString();
		else
			return null;
	}
	
	public String getTimeCategory(){
		Object timeCat = tweet.get("time_cat");
		
		return timeCat.toString();
	}
	
	public List<String> getConcepts(){
		List<String> concepts = new ArrayList<String>();
		
		BasicDBList conceptsList = (BasicDBList)tweet.get("concepts");
		
		for(int i=0; i<conceptsList.size(); i++){
			String concept = conceptsList.get(i).toString();
			concepts.add(concept);
		}
		
		return concepts;
	}
}
